// pages/myorder/myorder.js

const host = require('../../config.js').host;
const network = require('../../utils/network.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    orderList:[]
  },
  gotoorderdetail(e){
    
    // console.log("===="+this.data.orderList[e.currentTarget.dataset.index].id)
    wx.navigateTo({
      url: '/pages/myorderdetail/myorderdetail?orderId='+this.data.orderList[e.currentTarget.dataset.index].customerPaymentRecordId,
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.getList()
  },
  getList() {
    let that = this;
    network.requestGet(host + '/xcx/customerPaymentRecord/list', {
      "pageSize":"10",
      "pageNum":that.data.page,
      "orderList":"true",
      "yezhuBalance":"true"
    }, res => { 
      if (res.data.code == 200) {
        console.log("订单列表"+res)
        if (that.data.page == 1) {
          that.setData({
            orderList:res.data.rows
          })

        } else {
          that.setData({
            orderList:that.data.orderList.concat(res.data.rows)
          }) 

        }
        wx.stopPullDownRefresh();
      } else {
        wx.showToast({
          title: res.data.msg ? res.data.msg : '请求失败',
          icon: "none",
          duration: 1200
        })
      }
    })
  },
  onPullDownRefresh() {
    
    this.setData({
      page:1
    })
    this.getList()
  },
  onReachBottom() {
    //滚动到底部
    // 
    this.data.page = this.data.page + 1; 
    this.getList()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})